﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace HelloMods
{
    public static class Extensions
    {
        public static IEnumerable<GameObject> FindChild(this GameObject component, Func<GameObject, bool> filter, int deep = 99)
        {
            var list = new List<GameObject>();
            findChild(component.transform, list, deep, filter);
            return list;
        }

        static void findChild(Transform transform, List<GameObject> list, int deep, Func<GameObject, bool> filter)
        {
            if (deep < 0)
                return;
            foreach (Transform c in transform)
            {
                if (filter(c.gameObject))
                    list.Add(c.gameObject);
                findChild(c.transform, list, deep - 1, filter);
            }
        }
    }
}
